package com.bingxue.edu.tools;

import cn.hutool.core.util.StrUtil;
import com.bingxue.edu.management.education.model.entity.ClassInfo;
import com.bingxue.edu.management.education.service.ClassInfoService;
import com.bingxue.edu.management.education.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

import static com.bingxue.edu.management.education.model.entity.table.LessonTableDef.LESSON;

/**
 * @author panbo
 * @since 2025/1/24
 */
@SpringBootTest
public class AssistTeacherFixedTool {

    @Autowired
    private ClassInfoService classInfoService;
    @Autowired
    private LessonService lessonService;

//    @Test
//    @Transactional(rollbackFor = Exception.class)
    public void fixed() {
        List<ClassInfo> classList = classInfoService.list();
        for (ClassInfo classInfo : classList) {
            if(StrUtil.isNotEmpty(classInfo.getAssistTeacherId())) {
                lessonService.updateChain()
                        .set(LESSON.ASSIST_TEACHER_ID, classInfo.getAssistTeacherId())
                        .where(LESSON.CLASS_ID.eq(classInfo.getId()))
                        .update();
            }
         }
    }
}
